import 'package:flutter/material.dart';

class MyHomePage extends StatelessWidget {
  const MyHomePage({super.key});

  @override
  Widget build(BuildContext context) {
    List<int> list = [];
    for (var i = 1; i < 21; i++) {
      list.add(i);
    }
    // final size = MediaQuery.of(context).size;
    // NumberFormat formatter = NumberFormat("0000");
    return ListView(
      padding: const EdgeInsets.all(10),
      children: [
        Row(
          children: [
            Text(
              "热搜",
              style: Theme.of(context).textTheme.titleLarge,
            )
          ],
        ),
        const Divider(),
        Wrap(
          spacing: 10,
          runSpacing: 10,
          children: [
            Button(
              "女装",
              onPressed: () {},
            ),
            Button(
              "笔记本",
              onPressed: () {},
            ),
            Button(
              "玩具",
              onPressed: () {},
            ),
            Button(
              "文学",
              onPressed: () {},
            ),
            Button(
              "时尚",
              onPressed: () {},
            ),
            Button(
              "男装",
              onPressed: () {},
            ),
            Button(
              "xxxxxx",
              onPressed: () {},
            ),
            Button(
              "手机",
              onPressed: () {},
            ),
            Button(
              "电脑",
              onPressed: () {},
            ),
          ],
        ),
        const SizedBox(
          height: 20,
        ),
        const Divider(),
        Row(
          children: [
            Text(
              "历史记录",
              style: Theme.of(context).textTheme.titleLarge,
            )
          ],
        ),
        const Divider(),
        const Column(
          children: [
            ListTile(
              title: Text("女装"),
            ),
            Divider(),
            ListTile(
              title: Text("玩具"),
            ),
            Divider(),
            ListTile(
              title: Text("电脑"),
            ),
            Divider(),
          ],
        ),
        const SizedBox(
          height: 10,
        ),
        Padding(
          padding: const EdgeInsets.all(40),
          child: OutlinedButton.icon(
            style: ButtonStyle(
                foregroundColor: MaterialStateProperty.all(Colors.black45)),
            onPressed: () {},
            icon: const Icon(Icons.delete),
            label: const Text("清空历史记录"),
          ),
        )
      ],
    );
  }
}

/// 自定义按钮组件
class Button extends StatelessWidget {
  String text;
  void Function()? onPressed = () => {};

  Button(this.text, {super.key, this.onPressed});

  @override
  Widget build(BuildContext context) {
    return ElevatedButton(
        style: ButtonStyle(
            backgroundColor: MaterialStateProperty.all(
                const Color.fromRGBO(236, 102, 34, 0.5)),
            foregroundColor:
                MaterialStateProperty.all(const Color.fromRGBO(219, 10, 23, 1)),
            padding: MaterialStateProperty.all(const EdgeInsets.all(0)),
            shape: MaterialStateProperty.all(RoundedRectangleBorder(
                borderRadius: BorderRadius.circular(2)))),
        onPressed: onPressed,
        child: Text(text));
  }
}
